﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Data.SqlClient;
using System.Drawing;
using System.Linq;
using System.Runtime.InteropServices;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

using System.Net;
using System.Net.Sockets;
using System.Diagnostics;
using System.IO;
using CrystalDecisions.Shared;

namespace dreametryVersion2
{
    public partial class frmMain : Form
    {
        String refreshQuery;

        Socket sck;
        EndPoint epLocal, epRemote;
        String plocal, pRemote;

        public frmMain()
        {
            InitializeComponent();
            sck = new Socket(AddressFamily.InterNetwork, SocketType.Dgram, ProtocolType.Udp);
            sck.SetSocketOption(SocketOptionLevel.Socket, SocketOptionName.ReuseAddress, true);
        }

        protected void UserControl_ButtonClick(object sender, EventArgs e)
        {
            //handle the event 
        }

        public void getInfo()
        {
            lblEmployeeName.Text = global.fullname;
            picEmployee.Image = Image.FromStream(global.getEmployeePicture(global.picture));
            this.BackColor = ColorTranslator.FromHtml(global.themeColor);
            pnlWorkFlowHeader.BackColor = ColorTranslator.FromHtml(global.themeColor);
            pnlHomeHeader.BackColor = ColorTranslator.FromHtml(global.themeColor);
            pnlWorkFlowHeader.BackColor = ColorTranslator.FromHtml(global.themeColor);
            pnlHeader.BackColor = ColorTranslator.FromHtml(global.themeColor);
            pnlTools.BackColor = ColorTranslator.FromHtml(global.themeColor);
        }

        private void frmMain_Load(object sender, EventArgs e)
        {
            this.Location = new Point(0, 0);
            this.Size = Screen.PrimaryScreen.WorkingArea.Size;
            getInfo();
            chat.updateipAddress();

            btnHome.PerformClick();

            // ======Connection to CHAT
            try
            {
                epLocal = new IPEndPoint(IPAddress.Parse(chat.GetLocalIP()), Convert.ToInt32(plocal));
                sck.Bind(epLocal);

                epRemote = new IPEndPoint(IPAddress.Parse(chat.getAdminIP()), Convert.ToInt32(pRemote));
                sck.Connect(epRemote);

                byte[] buffer = new byte[1500];
                sck.BeginReceiveFrom(buffer, 0, buffer.Length, SocketFlags.None, ref epRemote, new AsyncCallback(MessageCallback), buffer);
            }
            catch (Exception exp)
            {
                Console.Write(exp);
            }

            //display buttons
            String query = "SELECT RoleTable.AdminUser, RoleTable.Designer, RoleTable.Uploader, RoleTable.Verifier FROM employee INNER JOIN RoleTable ON employee.emp_id = RoleTable.emp_id where employee.emp_id ='" + global.employeeID + "'";
            DataTable data;
            using (SqlConnection connection = new SqlConnection(global.conString))
            {
                //sql command and fill data to datatable
                SqlCommand command = new SqlCommand(query, connection);
                command.Connection.Open();
                SqlDataAdapter adapter = new SqlDataAdapter(command);
                data = new DataTable();
                data.Clear();
                adapter.Fill(data);
            }

            btnHome.BringToFront();
            if (data.Rows[0][1].ToString() == "y")
            {
                btnDesigner.Visible = true;
                btnDesigner.BringToFront();
            }
            if (data.Rows[0][3].ToString() == "y")
            {
                btnVerify.Visible = true;
                btnVerify.BringToFront();
            }
            if (data.Rows[0][2].ToString() == "y")
            {
                btnUpload.Visible = true;
                btnUpload.BringToFront();
            }
            if (data.Rows[0][0].ToString() == "y")
            {
                btnAdmin.Visible = true;
                btnAdmin.BringToFront();
            }
            btnMyFolder.BringToFront();
            btnSearch.BringToFront();
            btnNote.BringToFront();

            //others
            //search
            btnSearchAi.BackColor = ColorTranslator.FromHtml(global.themeColor);
            btnSearchJPG.BackColor = ColorTranslator.FromHtml(global.themeColor);
            btnSearchPNG.BackColor = ColorTranslator.FromHtml(global.themeColor);
            btnSearchPsd.BackColor = ColorTranslator.FromHtml(global.themeColor);
            pnlKeyword.BackColor = ColorTranslator.FromHtml(global.themeColor);
            pnlDesignName.BackColor = ColorTranslator.FromHtml(global.themeColor);


            string verify;
            string commandText = "SELECT RoleTable.AdminChat FROM employee INNER JOIN RoleTable ON employee.emp_id = RoleTable.emp_id where employee.emp_id ='" + global.employeeID + "'";

            using (SqlConnection connection = new SqlConnection(global.conString))
            {
                SqlCommand command = new SqlCommand(commandText, connection);

                command.Connection.Open();
                verify = command.ExecuteScalar().ToString();



                if (verify == "y")
                {
                    plocal = "100";
                    pRemote = "200";
                }
                else
                {
                    plocal = "200";
                    pRemote = "100";
                }

            }
        }


        private void btnExit_Click(object sender, EventArgs e)
        {
            CloseApp();
        }

        private static void CloseApp()
        {

            //=======Check if closing user is admin that can chat
            string count = "";
            string cmdText = "SELECT Count(*) FROM employee INNER JOIN RoleTable ON employee.emp_id = RoleTable.emp_id WHERE RoleTable.AdminChat = 'y' AND employee.emp_id = @id";

            using (SqlConnection connection = new SqlConnection(global.conString))
            {
                SqlCommand command = new SqlCommand(cmdText, connection);
                command.CommandType = CommandType.Text;
                command.Parameters.AddWithValue("@id", global.employeeID);

                try
                {
                    command.Connection.Open();
                    count = command.ExecuteScalar().ToString();
                }
                catch
                {

                }
                finally
                {
                    command.Connection.Close();
                }



            }

            if (count == "0") //  <======if user is not the admin that cna chat set ip address to NULL
            {
                string commandText = "UPDATE employee SET pc_ip_address = NULL WHERE emp_id = @id";

                using (SqlConnection connection = new SqlConnection(global.conString))
                {
                    SqlCommand command = new SqlCommand(commandText, connection);
                    command.CommandType = CommandType.Text;
                    command.Parameters.AddWithValue("@id", global.employeeID);

                    try
                    {
                        command.Connection.Open();
                        command.ExecuteNonQuery();
                    }
                    catch
                    {

                    }
                    finally
                    {
                        command.Connection.Close();
                    }
                    Application.Exit();

                }
            }
            else   // <====Else if the user is the admin that can chat, retain ip address
            {
                Application.Exit();
            }
        } /***  < ======  This is the function for close with query, 
                                            to verify if the user that will close tha system is the admin that can chat,
                                            THIS IS TO AVOID ERROR WHEN OTHER NON AdminChat USER WILL LOGIN 
                                            ***/

        private void btnNote_Click(object sender, EventArgs e)
        {
            frmNoteOnTop form = new frmNoteOnTop();
            form.Show();
        }

        private void btnMinimize_Click(object sender, EventArgs e)
        {
            this.WindowState = FormWindowState.Minimized;
        }

        private void btnLogout_Click(object sender, EventArgs e)
        {
            String returnValue = message.YesNo("logout", "Do you want to logout?");
            
            if(returnValue == "Yes")
            {
                global.employeeID = null;
                global.fullname = null;
                global.folder = null;

                frmLogin form = new frmLogin();
                form.Show();
                this.Hide();
            }
        }

        private void picEmployee_MouseHover(object sender, EventArgs e)
        {
            toolTip.Show("Edit your profile",picEmployee);
        }

        private void picEmployee_Click(object sender, EventArgs e)
        {
            frmUpdateEmployee form = new frmUpdateEmployee();
            form.Show();
        }

        private void btnHome_Click(object sender, EventArgs e)
        {
            btnMacro.BackColor = ColorTranslator.FromHtml(global.themeColor);
            btnTools.BackColor = ColorTranslator.FromHtml(global.themeColor);
            pnlMacro.Visible = false;
            pnlTools.Visible = false;
            //panels
            pnlHome.Visible = true;
            pnlWorkFlow.Visible = false;
            //button back color
            btnHome.BackColor = ColorTranslator.FromHtml(global.darkerColor(global.themeColor));
            btnDesigner.BackColor = Color.WhiteSmoke;
            btnVerify.BackColor = Color.WhiteSmoke;
            btnUpload.BackColor = Color.WhiteSmoke;
            btnAdmin.BackColor = Color.WhiteSmoke;
            //button forecolor
            btnHome.ForeColor = Color.White;
            btnDesigner.ForeColor = Color.FromArgb(64, 64, 64);
            btnVerify.ForeColor = Color.FromArgb(64, 64, 64);
            btnUpload.ForeColor = Color.FromArgb(64, 64, 64);
            btnAdmin.ForeColor = Color.FromArgb(64, 64, 64);

            //notice
            ucWorkFlow.Focus();

            //notice board
            txtNotice.Clear();
            txtNotice.Text = File.ReadAllText(@"\\DB-SERVER\Users\Public\Documents\MIS-NB\notice.txt");
            btnNoticeSave.Visible = false;
        }

        private void btnDesigner_Click(object sender, EventArgs e)
        {
            btnMacro.BackColor = ColorTranslator.FromHtml(global.themeColor);
            btnTools.BackColor = ColorTranslator.FromHtml(global.themeColor);
            pnlMacro.Visible = false;
            pnlTools.Visible = false;
            btnMacro.Visible = false;
            lblHeaderWork.Visible = true;
            lblHeaderWork.Text = "My Created Task";
            btnSwitch.Visible = true;
            //panels
            pnlWorkFlow.Visible = true;
            pnlHome.Visible = false;
            //button backcolor
            btnDesigner.BackColor = ColorTranslator.FromHtml(global.darkerColor(global.themeColor));
            btnHome.BackColor = Color.WhiteSmoke;
            btnVerify.BackColor = Color.WhiteSmoke;
            btnUpload.BackColor = Color.WhiteSmoke;
            btnAdmin.BackColor = Color.WhiteSmoke;
            //button forecolor
            btnHome.ForeColor = Color.FromArgb(64, 64, 64);
            btnDesigner.ForeColor = Color.White;
            btnVerify.ForeColor = Color.FromArgb(64, 64, 64);
            btnUpload.ForeColor = Color.FromArgb(64, 64, 64);
            btnAdmin.ForeColor = Color.FromArgb(64, 64, 64);
            //create button
            btnCreate.Visible = true;
            btnRefresh.Visible = true;
            btnTools.Visible = false;

            refreshQuery = "SELECT * FROM ViewEmployeeTaskData WHERE emp_id =  '" + global.employeeID + "' and Reported LIKE 'no' and part LIKE 'Creator'";
            txtCount.Text = this.ucWorkFlow.getWorkFlow(refreshQuery);
        }

        private void btnCreate_Click(object sender, EventArgs e)
        {
            FrmCreateTask form = new FrmCreateTask();
            form.Show();
        }

        private void btnRefresh_Click(object sender, EventArgs e)
        {
            txtCount.Text = this.ucWorkFlow.getWorkFlow(refreshQuery);
        }

        private void btnMyFolder_Click(object sender, EventArgs e)
        {
            Process.Start(@"Z:\_____Codiga\_____AI and PSD Files\____TASKS IN PROGRESS\" +global.folder);
        }

        private void btnVerify_Click(object sender, EventArgs e)
        {
            btnMacro.BackColor = ColorTranslator.FromHtml(global.themeColor);
            btnTools.BackColor = ColorTranslator.FromHtml(global.themeColor);
            pnlMacro.Visible = false;
            pnlTools.Visible = false;
            btnMacro.Visible = false;
            lblHeaderWork.Visible = false;
            btnSwitch.Visible = false;
            //panels
            pnlWorkFlow.Visible = true;
            pnlHome.Visible = false;
            //button back colors
            btnDesigner.BackColor = Color.WhiteSmoke;
            btnHome.BackColor = Color.WhiteSmoke;
            btnVerify.BackColor = ColorTranslator.FromHtml(global.darkerColor(global.themeColor));
            btnUpload.BackColor = Color.WhiteSmoke;
            btnAdmin.BackColor = Color.WhiteSmoke;
            //button forecolors
            btnHome.ForeColor = Color.FromArgb(64, 64, 64);
            btnDesigner.ForeColor = Color.FromArgb(64, 64, 64);
            btnVerify.ForeColor = Color.White;
            btnUpload.ForeColor = Color.FromArgb(64, 64, 64);
            btnAdmin.ForeColor = Color.FromArgb(64, 64, 64);
            //create button
            btnCreate.Visible = false;
            btnRefresh.Visible = true;
            btnTools.Visible = false;

            refreshQuery = "SELECT * FROM ViewEmployeeTaskData WHERE Reported LIKE 'no' AND forUser LIKE 'Verifier' and part LIKE 'Creator'";
            txtCount.Text = this.ucWorkFlow.getWorkFlow(refreshQuery);
        }

        private void frmMain_Activated(object sender, EventArgs e)
        {
           // ucWorkFlow.Focus();
           //
           // //notice board
           // txtNotice.Clear();
           // txtNotice.Text = File.ReadAllText(@"\\DB-SERVER\Users\Public\Documents\MIS-NB\notice.txt");
           // btnNoticeSave.Visible = false;
        }

        private void btnUpload_Click(object sender, EventArgs e)
        {
            btnMacro.BackColor = ColorTranslator.FromHtml(global.themeColor);
            btnTools.BackColor = ColorTranslator.FromHtml(global.themeColor);
            pnlMacro.Visible = false;
            pnlTools.Visible = false;
            btnMacro.Visible = true;
            lblHeaderWork.Visible = false;
            btnSwitch.Visible = false;
            //panels
            pnlWorkFlow.Visible = true;
            pnlHome.Visible = false;
            //button back colors
            btnDesigner.BackColor = Color.WhiteSmoke;
            btnHome.BackColor = Color.WhiteSmoke;
            btnVerify.BackColor = Color.WhiteSmoke;
            btnUpload.BackColor = ColorTranslator.FromHtml(global.darkerColor(global.themeColor));
            btnAdmin.BackColor = Color.WhiteSmoke;
            //button forecolors
            btnHome.ForeColor = Color.FromArgb(64, 64, 64);
            btnDesigner.ForeColor = Color.FromArgb(64, 64, 64);
            btnVerify.ForeColor = Color.FromArgb(64, 64, 64);
            btnUpload.ForeColor = Color.White;
            btnAdmin.ForeColor = Color.FromArgb(64, 64, 64);
            //create button
            btnCreate.Visible = false;
            btnRefresh.Visible = true;
            btnTools.Visible = false;

            refreshQuery = "SELECT * FROM ViewEmployeeTaskData WHERE Reported LIKE 'no' AND forUser LIKE 'Uploader' and part LIKE 'Creator'";
            txtCount.Text = this.ucWorkFlow.getWorkFlow(refreshQuery);
        }

        private void btnSearch_Click(object sender, EventArgs e)
        {
            pnlSearch.Top = btnSearch.Top + 30;
            if(pnlSearch.Visible == false)
            {
                pnlSearch.Visible = true;
                btnSearch.BackColor = ColorTranslator.FromHtml(global.themeColor);
                btnSearch.ForeColor = Color.White;
                txtKeyword.Focus();
            }
            else
            {
                pnlSearch.Visible = false;
                btnSearch.BackColor = Color.WhiteSmoke;
                btnSearch.ForeColor = Color.FromArgb(64, 64, 64);
            }
        }

        private void btnSearchPNG_Click(object sender, EventArgs e)
        {
            string folder = Uri.EscapeDataString(@"Z:\_____Codiga");
            string file = txtKeyword.Text + @" System.FileName:~=""" + txtDesignName.Text + @""" type:png";
            string uri = "search:query=" + file + "&crumb=location:" + folder;
            Process.Start(new ProcessStartInfo(uri));
        }

        private void btnSearchJPG_Click(object sender, EventArgs e)
        {
            string folder = Uri.EscapeDataString(@"Z:\_____Codiga");
            string file = txtKeyword.Text + @" System.FileName:~=""" + txtDesignName.Text + @""" type:jpg";
            string uri = "search:query=" + file + "&crumb=location:" + folder;
            Process.Start(new ProcessStartInfo(uri));
        }

        private void btnSearchAi_Click(object sender, EventArgs e)
        {
            string folder = Uri.EscapeDataString(@"Z:\_____Codiga");
            string file = txtKeyword.Text + @" System.FileName:~=""" + txtDesignName.Text + @""" type:ai";
            string uri = "search:query=" + file + "&crumb=location:" + folder;
            Process.Start(new ProcessStartInfo(uri));
        }

        private void btnSearchPsd_Click(object sender, EventArgs e)
        {
            string folder = Uri.EscapeDataString(@"Z:\_____Codiga");
            string file = txtKeyword.Text + @" System.FileName:~=""" + txtDesignName.Text + @""" type:psd";
            string uri = "search:query=" + file + "&crumb=location:" + folder;
            Process.Start(new ProcessStartInfo(uri));
        }

  

        private void verifyToolStripMenuItem_Click(object sender, EventArgs e)
        {
            if (pnlSearch.Visible == false)
            {
                pnlSearch.Visible = true;
                btnSearch.BackColor = ColorTranslator.FromHtml(global.themeColor);
                btnSearch.ForeColor = Color.White;
            }
            else
            {
                pnlSearch.Visible = false;
                btnSearch.BackColor = Color.WhiteSmoke;
                btnSearch.ForeColor = Color.FromArgb(64, 64, 64);
            }
            Show();
            WindowState = FormWindowState.Normal;
        }

        private void designToolStripMenuItem_Click(object sender, EventArgs e)
        {
            Process.Start(@"Z:\_____Codiga\_____AI and PSD Files\____TASKS IN PROGRESS\" + global.folder);
        }

        private void frmMain_Resize(object sender, EventArgs e)
        {
          
      
        }

        private void notifyIcon1_DoubleClick(object sender, EventArgs e)
        {
            Show();
            WindowState = FormWindowState.Normal;
        }

        private void txtKeyword_TextChanged(object sender, EventArgs e)
        {

        }

        private void exitToolStripMenuItem_Click(object sender, EventArgs e)
        {
            frmNoteOnTop form = new frmNoteOnTop();
            form.Show();
        }

        private void exitToolStripMenuItem1_Click(object sender, EventArgs e)
        {
            CloseApp();
        }

        private void btnTools_Click(object sender, EventArgs e)
        {
            if(pnlTools.Visible == false)
            {
                pnlTools.Visible = true;
                btnTools.BackColor = ColorTranslator.FromHtml(global.darkerColor(global.themeColor));
            }
            else
            {
                pnlTools.Visible = false;
                btnTools.BackColor = ColorTranslator.FromHtml(global.themeColor);
            }
        }

        private void btnNoticeSave_Click(object sender, EventArgs e)
        {
            string path = @"\\DB-SERVER\Users\Public\Documents\MIS-NB\notice.txt";

            File.WriteAllText(path, txtNotice.Text);

            btnNoticeSave.Visible = false;
            btnNoticeSave.Focus();
        }

        private void txtNotice_TextChanged(object sender, EventArgs e)
        {
            btnNoticeSave.Visible = true;
        }

        private void btnGenerateReport_Click(object sender, EventArgs e)
        {
            pnlTools.Visible = false;
            btnTools.BackColor = ColorTranslator.FromHtml(global.themeColor);
            
            String query = "UPDATE TaskTable SET date_updated = GETDATE() From TaskTable INNER JOIN WorkFlow ON TaskTable.status_id = WorkFlow.status_id WHERE WorkFlow.flow_name NOT LIKE 'Fulfilled' AND TaskTable.reported LIKE 'no'";

            using (SqlConnection connection = new SqlConnection(global.conString))
            {
                SqlCommand command = new SqlCommand(query, connection);
                command.CommandType = CommandType.Text;
                command.Connection.Open();
                command.ExecuteNonQuery();
            }
            
            string comString = "SELECT * FROM ViewEmployeeTaskData WHERE reported LIKE 'no'";

            using (SqlConnection con = new SqlConnection(global.conString))
            using (SqlDataAdapter adapter = new SqlDataAdapter(comString, con))
            {
                DreametryDBDataSet ds = new DreametryDBDataSet();
                ds.ViewEmployeeTaskData.Clear();
                ds.EnforceConstraints = false;
                adapter.Fill(ds.ViewEmployeeTaskData);
                EmployeeTaskReport report = new EmployeeTaskReport();
                report.SetDataSource(ds);

                crystalReportViewer1.ReportSource = report;
            }
            
            crystalReportViewer1.AllowedExportFormats = (int)(ViewerExportFormats.PdfFormat);
            crystalReportViewer1.ExportReport();

            string x = message.YesNo("Confirmation", "This will delete Fulfilled task. Are you Sure?");

            if (x == "Yes")
            {
                //    ======= UPDATED FULLFILLED TASK TO REPORTED
                using (SqlConnection conn = new SqlConnection(global.conString))
                {
                    conn.Open();
                    SqlCommand command = new SqlCommand("ReportedYes", conn);
                    command.CommandType = CommandType.StoredProcedure;
                    command.ExecuteNonQuery();
                }
                this.ucWorkFlow.getWorkFlow("SELECT * FROM ViewEmployeeTaskData WHERE flow_name LIKE 'Fulfilled' and reported LIKE 'no'");
            }
           
        }

        private void btnAssignTask_Click(object sender, EventArgs e)
        {
            pnlTools.Visible = false;
            btnTools.BackColor = ColorTranslator.FromHtml(global.themeColor);

            frmAssignTask frm = new frmAssignTask();
            frm.Show();
        }

        private void btnChat_Click(object sender, EventArgs e)
        {
            pnlTools.Visible = false;
            btnTools.BackColor = ColorTranslator.FromHtml(global.themeColor);

            frmChat frm = new frmChat();
            frm.Show();
        }

        private void btnMin_Click(object sender, EventArgs e)
        {
            this.WindowState = FormWindowState.Minimized;
        }

        private void btnSwitch_Click(object sender, EventArgs e)
        {
            if(lblHeaderWork.Text == "My Created Task")
            {
                refreshQuery = "SELECT * FROM ViewEmployeeTaskData WHERE emp_id =  '" + global.employeeID + "' and Reported LIKE 'no' and part LIKE 'Collaborator'";
                txtCount.Text = this.ucWorkFlow.getWorkFlow(refreshQuery);
                lblHeaderWork.Text = "My Collaborated Task";
            }
            else
            {
                refreshQuery = "SELECT * FROM ViewEmployeeTaskData WHERE emp_id =  '" + global.employeeID + "' and Reported LIKE 'no' and part LIKE 'Creator'";
                txtCount.Text = this.ucWorkFlow.getWorkFlow(refreshQuery);
                lblHeaderWork.Text = "My Created Task";
            }
        }
        List<Button> listButtonMacro = new List<Button>();
        DataTable data = new DataTable();
        private void btnMacro_Click(object sender, EventArgs e)
        {
            pnlMacro.BackColor = ColorTranslator.FromHtml(global.themeColor);
            pnlMacro.Controls.Clear();
            listButtonMacro.Clear();
            if(pnlMacro.Visible == false)
            {
                btnMacro.BackColor = ColorTranslator.FromHtml(global.darkerColor(global.themeColor));
                pnlMacro.Visible = true;
                
                data = new DataTable();
                string conString = "SELECT * FROM Macro";

                using (SqlConnection connection = new SqlConnection(global.conString))
                {
                    //sql command and fill data to datatable
                    SqlCommand command = new SqlCommand(conString, connection);
                    command.Connection.Open();
                    SqlDataAdapter adapter = new SqlDataAdapter(command);
                    data = new DataTable();
                    data.Clear();
                    adapter.Fill(data);
                }

                pnlMacro.Height = ((data.Rows.Count)*46)+1;

                for (int i = 0; i < data.Rows.Count; i++)
                {
                    Button butt = new Button
                    {
                        Text = data.Rows[i][1].ToString(),
                        Dock = DockStyle.Top,
                        Height = 46,
                        BackColor = Color.White,
                        FlatStyle = FlatStyle.Flat,
                        Cursor = Cursors.Hand
                    }; butt.FlatAppearance.BorderSize = 0;
                    listButtonMacro.Add(butt);
                    listButtonMacro[i].Click += macro_Click;

                    pnlMacro.Controls.Add(butt);
                }
            }
            else
            {
                pnlMacro.Visible = false;
                btnMacro.BackColor = ColorTranslator.FromHtml(global.themeColor);
            }
        }

        public void macro_Click(object sender, EventArgs e)
        {
            Button butt = sender as Button;
            int index = listButtonMacro.IndexOf(butt);
            try
            {
                Process.Start(data.Rows[index][2].ToString());
                this.WindowState = FormWindowState.Minimized;
            }
            catch
            {

            }
        }

        private void btnAdmin_Click(object sender, EventArgs e)
        {
            btnMacro.BackColor = ColorTranslator.FromHtml(global.themeColor);
            btnTools.BackColor = ColorTranslator.FromHtml(global.themeColor);
            pnlMacro.Visible = false;
            pnlTools.Visible = false;
            btnMacro.Visible = false;
            lblHeaderWork.Visible = false;
            btnSwitch.Visible = false;
            //panels
            pnlWorkFlow.Visible = true;
            pnlHome.Visible = false;
            //button backcolor
            btnDesigner.BackColor = Color.WhiteSmoke;
            btnHome.BackColor = Color.WhiteSmoke;
            btnVerify.BackColor = Color.WhiteSmoke;
            btnUpload.BackColor = Color.WhiteSmoke;
            btnAdmin.BackColor = ColorTranslator.FromHtml(global.darkerColor(global.themeColor));
            //button forecolor
            btnHome.ForeColor = Color.FromArgb(64, 64, 64);
            btnDesigner.ForeColor = Color.FromArgb(64, 64, 64);
            btnVerify.ForeColor = Color.FromArgb(64, 64, 64);
            btnUpload.ForeColor = Color.FromArgb(64, 64, 64);
            btnAdmin.ForeColor = Color.White;
            //create button
            btnCreate.Visible = false;
            btnRefresh.Visible = true;
            btnTools.Visible = true;

            refreshQuery = "SELECT * FROM ViewEmployeeTaskData WHERE flow_name LIKE 'Fulfilled' AND reported LIKE 'no' and part LIKE 'Creator'";
            txtCount.Text = this.ucWorkFlow.getWorkFlow(refreshQuery);
        }

        private void MessageCallback(IAsyncResult aResult)
        {
            try
            {
                int size = sck.EndReceiveFrom(aResult, ref epRemote);
                if (size > 0)
                {
                    byte[] receivedData = new byte[1464];

                    receivedData = (byte[])aResult.AsyncState;

                    ASCIIEncoding eEncoding = new ASCIIEncoding();
                    string receivedMessage = eEncoding.GetString(receivedData);

                    //  int x = listBox1.Items.Count - 1;
                    //  listBox1.Items.RemoveAt(x);

                    //  listBox1.Items.Add("Partner" + receivedMessage);

                    //RECIEVED CHAT MESSAGE
                    //MessageBox.Show(receivedMessage);

                    string verify;
                    string commandText = "SELECT RoleTable.AdminChat FROM employee INNER JOIN RoleTable ON employee.emp_id = RoleTable.emp_id where employee.emp_id ='" + global.employeeID + "'";

                    using (SqlConnection connection = new SqlConnection(global.conString))
                    {
                        SqlCommand command = new SqlCommand(commandText, connection);

                        command.Connection.Open();
                        verify = command.ExecuteScalar().ToString();



                        if (verify == "y")
                        {
                            message.adminMessage(receivedMessage, "100", "200");
                        }
                        else
                        {
                            message.adminMessage(receivedMessage, "200", "100");
                        }

                        //=============================


                    }
                    byte[] buffer = new byte[1500];
                    sck.BeginReceiveFrom(buffer, 0, buffer.Length, SocketFlags.None, ref epRemote, new AsyncCallback(MessageCallback), buffer);



                }
            }
            catch (Exception exp)
            {
                Console.Write(exp);
            }
        }

    }
}
